import math
def anint(x, lx):
    lhx=0.5*lx;
    while x>lhx:
        x-=lx
    while x<-lhx:
        x+=lx
    return x
def distancia(lbox,pos1,pos2):
    dis2=0
    drx=pos2[0]-pos1[0]
    drx=anint(drx,lbox[0])
    dry=pos2[1]-pos1[1]
    dry=anint(dry,lbox[1])
    drz=pos2[2]-pos1[2]
    drz=anint(drz,lbox[2])
    dis2=drx*drx+dry*dry+drz*drz
    return  [math.sqrt(dis2),drx,dry,drz]

name = "/home/jonk/remote/cspfsc/jcfernandez/simulaciones/espresso/LJ/uno/posicion.dat"
pos=[]
for line in file(name):
    line=line.replace('\n','')
    res=[]
    val=line.split(' ')
    for v in val:
        if v!='':
            res.append(float(v))
    pos.append([res[0],res[1],res[2]])


dmin=1.e7;
lbox=[17.3647,17.3647,17.3647]
for i in range(len(pos)-1):
    for j in range(i+1,len(pos)):
        [dis,dx,dy,dz] = distancia(lbox,pos[i],pos[j])
        if dis<dmin:
            dmin=dis
            imin=i
            jmin=j
print dmin,imin,jmin
[dis,dx,dy,dz] = distancia(lbox,pos[0],pos[1])
print dis